package com.example.demo.pojo.vo;

import com.example.demo.pojo.entity.QuestionBank;
import com.example.demo.pojo.entity.QuestionLabel;
import com.example.demo.pojo.entity.SubjectFile;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 携带题目与文件的信息，用于构建题库表
 * @author fjh
 */
@Data
@AllArgsConstructor
public class QuestionVO {
    private Integer id;
    //题目信息
    private Integer bankId;
    private String questionName;
    private String options;
    private String correctAnswer;
    private Double score;
    private String difficulty;
    private Integer category;
    private String parse;
    private Double answerNumber;
    private String dir;
    private String label;
    private List<String>optionList;
    private String htmlQuestionName;
    private String htmlOptions;
    private List<String>htmlOptionsList;
    private String htmlParse;
    //题型信息
    private List<Integer>labelIds;
    private List<String>labelNames;
    private Integer rootId;
    //文件信息
    private String fileName;
    private List<Integer> fileIdList;
    private String nodeId;
    private String fileCreateUser;
    //扩展信息
    //题目分类名称
    private String categoryName;
    public QuestionVO() {
        labelIds=new ArrayList<Integer>();
        labelNames=new ArrayList<String>();
        optionList=new ArrayList<>();
        htmlOptionsList=new ArrayList<>();
        fileIdList=new ArrayList<>();
    }
    //构建题目相关信息
    public void initBank(QuestionBank questionBank){
        this.bankId=questionBank.getId();
        this.questionName=questionBank.getName();
        this.options=questionBank.getOptions();
        this.correctAnswer= questionBank.getCorrectAnswer();
        this.score=questionBank.getScore();
        this.difficulty=questionBank.getDifficulty();
        this.category=questionBank.getCategory();
        this.parse=questionBank.getParse();
        this.answerNumber= questionBank.getAnswerNumber();
        this.label=questionBank.getLabel();
        this.htmlQuestionName=questionBank.getHtmlName();
        this.htmlOptions=questionBank.getHtmlOption();
        this.htmlParse=questionBank.getHtmlParse();
    }
    //构建题型相关信息
    public void initLabel(QuestionLabel questionLabel){
        this.labelIds.add(questionLabel.getId());
        this.labelNames.add(questionLabel.getName());
//        this.parentId=questionLabel.getParentId();
//        this.nodeId=questionLabel.getNodeId();
//        this.level=questionLabel.getLevel();
    }
    //构建选项数组
    public void initOptions(String options,String htmlOptions){
        if(options!=null){
            String[]option=options.split("\\|");
            this.optionList.addAll(Arrays.asList(option));
        }
        if(htmlOptions!=null){
            String[]htmlOption=htmlOptions.split("\\|");
            this.htmlOptionsList.addAll(Arrays.asList(htmlOption));
        }
    }
    //构建文件
    public void initFile(SubjectFile subjectFile){
        this.fileName=subjectFile.getFileName();
        this.fileIdList.add(subjectFile.getId());
        this.nodeId=subjectFile.getNodeId();
        this.fileCreateUser=subjectFile.getCreateUser();
    }

}
